package com.winsafe.scanlibrary;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.device.ScanManager;
import android.os.Handler;
import android.os.Message;

public class ScanResultReceiver extends BroadcastReceiver {
    public static final int READ_RESULT = 999;

    Handler mHandler = null;

    public ScanResultReceiver(Handler handler) {
        this.mHandler = handler;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(IDataScanner.RES_ACTION)) {
            final String scanResult = intent.getStringExtra("value");
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, scanResult));
        } else if (intent.getAction().equals(NewlandScanner.RES_ACTION_NEW_LAND)) {
            final String scanResultNl = intent.getStringExtra("SCAN_BARCODE1");
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, scanResultNl));
        } else if (intent.getAction().equals(SeuicScanner.RES_SCAN_SEUIC)) {
            final String scanResult = intent.getStringExtra("scannerdata");
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, scanResult));
        } else if (intent.getAction().equals(UrovoScanner.RES_SCAN_UROVO)) {
            final String scanResult =  intent.getStringExtra(ScanManager.BARCODE_STRING_TAG);
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, scanResult));
        } else {
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, ""));
        }
    }
}
